var _ = require('lodash');
var moment = require('moment');
var recordModel = require('./recordModel.js');
var configUtil = require('../../app/util/configUtil.js');

suite('calc_daily_diamond_use', function () {
    suite('calc_daily_diamond_use', function () {
        test('统计每日钻石消耗', function (done) {
            this.timeout(1000000);
            // var server_id = configUtil.load('game').server_id;
            var server_id = 10003;
            recordModel.getByEventType(server_id, 100501, function (err, model_list) {
                // console.log('model_list.length=', model_list.length);
                // console.log('model_list[0]=', model_list[0]);
                var sum_info = {};
                var total_diamond = 0;
                _.forEach(model_list, function (model) {
                    var this_day = moment(model.create_time).startOf('day').unix();
                    var diamond_num = +(model.diamond_num);
                    if (!sum_info[this_day]) {
                        sum_info[this_day] = 0;
                    }
                    sum_info[this_day] += diamond_num;
                    total_diamond += diamond_num;
                });

                _.forEach(sum_info, function (info, key) {
                    var day = moment.unix(+key).format('YYYY-MM-DD');
                    console.log(day, ' --- ', info);
                });

                console.log('total_diamond:', total_diamond);
                done();
            });
        });
    });
});
